<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">
    <meta content="IE=edge" http-equiv="X-UA-Compatible">
    <meta content="" name="keywords">
    <meta content="" name="description">
    <title th:text="评论修改"></title>
    <link rel="stylesheet" th:href="@{/component/pear/css/pear.css}">
</head>
<body>
<form action="" class="layui-form">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">ID</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" lay-verify="required" name="id"
                               placeholder="请输入ID" th:value="${param.id}" type="text" disabled="disabled">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">评论人：</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" lay-verify="required" name="nickname"
                               th:value="${param.nickname}" type="text" readonly>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">被回复：</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" lay-verify="required" name="replyName"
                               th:value="${param.replyName}" type="text" readonly>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">评论内容</label>
                    <div class="layui-input-block">
                        <textarea autocomplete="off" class="layui-textarea" lay-verify="required" name="content"
                                  placeholder="请输入评论" th:text="${param.content}" type="text"></textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button class="pear-btn pear-btn-primary pear-btn-sm" lay-filter="type-update" lay-submit=""
                    type="submit">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button class="pear-btn pear-btn-sm" type="reset">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
</form>
<script th:src="@{/component/layui/layui.js}"></script>
<script th:src="@{/component/pear/pear.js}"></script>
<script th:src="@{/admin/js/jquery.min.js}"></script>
<script th:inline="javascript">
    let basePath = [[${#httpServletRequest.getContextPath()}]];
    layui.use(['form', 'jquery'], function () {
        let form = layui.form;
        let $ = layui.jquery;

        form.on('submit(type-update)', function (data) {
            data = data.field;
            $.ajax({
                url: basePath + '/comment/update',
                data: {'id': data.id, 'content': data.content},
                dataType: 'json',
                type: 'put',
                success: function (result) {
                    if (result.code) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("comment-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })
</script>
</body>
</html>